package com.enjoyor.health.HGPT.web.rest;

import cn.dev33.satoken.stp.StpUtil;
import com.enjoyor.health.HGPT.core.entity.UserInfo;
import com.enjoyor.health.HGPT.service.BizReportService;
import com.enjoyor.health.HGPT.service.BizUserService;
import com.enjoyor.health.HGPT.web.CodeEnum;
import com.enjoyor.health.HGPT.web.RetResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.stream.Collectors;

/**
 * @author Zhu Min
 * @date 2023/12/26 18:56
 */
@Slf4j
@Api(value = "APP用户接口", tags = {"APP接口"})
@CrossOrigin
@RequestMapping("/app/data")
@RestController
public class AppDataController {

    @Autowired
    private BizReportService bizReportService;
    @Autowired
    private BizUserService bizUserService;
    /**
     * 获取指标范围
     */
    @RequestMapping(value = "/healthIndicator", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getHealthIndicator(String name){
        String userId = StpUtil.getLoginIdAsString();
        UserInfo userInfo = bizUserService.getByUserId(userId);
        if ("uricAcid".equals(name) ){
            if (userInfo == null){
                return new RetResult(CodeEnum.NO_USER_INFO);
            }else {
                return new RetResult().setResult(
                        bizReportService.getHealthIndicatorList().stream().filter(x->name.equals(x.getName()) &&
                                ((userInfo.getGender() != null && userInfo.getGender()==1)?"female":"male").equals(x.getRemark())).collect(Collectors.toList())
                );
            }
        }
        return new RetResult().setResult(bizReportService.getHealthIndicatorList().stream().filter(x->name.equals(x.getName())).collect(Collectors.toList()));
    }

}
